~ chicken-core (master) /manual/Module (scheme case-lambda)


 1[[tags: manual]]
 2[[toc:]]
 3
 4== Module (scheme case-lambda)
 5
 6<macro>(case-lambda <clause> ...)</macro>
 7
 8Syntax: Each <clause> is of the form (<formals> <body>), where <formals> and
 9<body> have the same syntax as in a lambda expression.
10
11Semantics: A case-lambda expression evaluates to a procedure that accepts a
12variable number of arguments and is lexically scoped in the same manner as a
13procedure resulting from a lambda expression. When the procedure is called, the
14first <clause> for which the arguments agree with <formals> is selected, where
15agreement is specified as for the <formals> of a lambda expression. The
16variables of <formals> are bound to fresh locations, the values of the
17arguments are stored in those locations, the <body> is evaluated in the
18extended environment, and the results of <body> are returned as the results of
19the procedure call.
20
21It is an error for the arguments not to agree with the <formals> of any
22<clause>.
23
24 (define range
25   (case-lambda
26    ((e) (range 0 e))
27    ((b e) (do ((r '() (cons e r))
28                (e (- e 1) (- e 1)))
29               ((< e b) r)))))
30 
31 (range 3)     ==> (0 1 2)
32 (range 3 5)   ==> (3 4)
33
34---
35Previous: [[Module (scheme base)]]
36
37Next: [[Module (scheme char))]]
Trap